package Java网络实例;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;
 /**
  * Java 实例 - 网页抓取
  *Java 实例 Java 实例
  *以下实例演示了如何使用 net.URL 类的 URL() 构造函数来抓取网页：
  * @author 宋利军
  *
  */
public class 网页抓取 {
   public static void main(String[] args) 
   throws Exception {
      URL url = new URL("http://wap.gd.chinamobile.com");
      BufferedReader reader = new BufferedReader
      (new InputStreamReader(url.openStream()));
      BufferedWriter writer = new BufferedWriter
      (new FileWriter("data.html"));
      String line;
      while ((line = reader.readLine()) != null) {
         System.out.println(line);
         writer.write(line);
         writer.newLine();
      }
      reader.close();
      writer.close();
   }
}
